max_record_count = 1000000
current_record_count = 0
table_index = 0
index_dict = {}
with open('from_device_file/secret_card_counter', 'r', encoding='utf8') as f:
    total = 0
    for line in f:
        line_split = line.split('=')
        # if len(line_split[0]) < 5:
        #     continue
        secret_card = line_split[0]
        count = int(line_split[1])
        current_record_count += count
        if current_record_count + count > max_record_count:
            current_record_count = 0
            table_index += 1
        index_dict[secret_card] = table_index
        total += 1
        if total % 100000 == 0:
            print('total is {}'.format(total))

print('write table index result to file')
with open('index_result.txt', 'w', encoding='utf8') as f:
    for secret_card, table_index in index_dict.items():
        f.write('{}={}\n'.format(secret_card, table_index))

print('finish...')